Package xunome.graphics

Source Code of xunome.graphics.GraphicCard

package xunome.graphics;

/**
*
* @author Sem iNick
*/
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Font;
import xunome.game.Card;

public class GraphicCard {
   
    private Image render;
    public final static int BLUE =  0x35B3B3;
    public final static int GREEN = 0x00FF00;
    public final static int RED = 0xFF0000;
    public final static int YELLOW = 0xECF00C;
    private static final int colors[] = {
                                BLUE, //Blue Color
                                GREEN, //Green Color
                                RED, //Red Color
                                YELLOW //Yellow Color
                             };

    public static GraphicCard createGraphicCard(Card card) {
       
       Image srcImage = null;
      
        try {
            String p2 = "";
            switch(card.getColor()) {
                case Card.BLUE:
                    p2 = "blue";
                break;

                case Card.GREEN:
                    p2 = "green";
               break;

                case Card.RED:
                    p2 = "red";
               break;

                case Card.YELLOW:
                    p2 = "yellow";
               break;

                case Card.NONE:
               break;

                default:
                    throw new IllegalArgumentException("Invalid color for graphic card.");
            }

            String p1 = "";
            switch(card.getType()) {
                case Card.GET2:
                    p1 = "get2";
                break;

                case Card.REVERSE:
                    p1 = "reverse";
                break;

                case Card.SKIP:
                    p1 = "skip";
                break;

                case Card.JOKER:
                    p1 = "joker";
                break;

                case Card.JOKER4:
                    p1 = "joker4";
                break;

                case Card.NORMAL:
                    p1 = "base";
                break;

                case Card.BACK:
                    p1 = "backcard";
                break;

                default:
                    throw new IllegalArgumentException("Invalid type for graphic card");
            }

            srcImage = Image.createImage("/res/"+p1+p2+".png");
        } catch(IOException io) {

            //#ifdef DEBUG
            System.out.println("Exception in GraphicCard");
            //#endif
        }

        GraphicCard newCard = new GraphicCard();
        newCard.render = Image.createImage(srcImage.getWidth(), srcImage.getHeight());
        Graphics gCard = newCard.render.getGraphics();

        //Draw base image
        gCard.drawImage(srcImage, 0, 0, Graphics.TOP|Graphics.LEFT);


        //Draw the number
        if(card.getNumber() != Card.NO_NUMBER) {
           gCard.setColor(255, 255, 255);
           String numbers = Integer.toString(card.getNumber());
           //Draw top number
           gCard.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
           gCard.drawString(numbers, 2, 2, Graphics.TOP|Graphics.LEFT);
           gCard.setColor(colors[card.getColor()]);
           //Draw center number
           gCard.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
           gCard.drawString(numbers, 11, 11, Graphics.TOP|Graphics.LEFT);
        }

        return newCard;
    }

    public Image getRender() {
        return this.render;
    }
}
TOP

Related Classes of xunome.graphics.GraphicCard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.